<%@page import="bean.Advertisement"  %>
<%@page import="bean.CartItem"  %>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<%@ include file="/title.html" %>
</head>
<body>
<table width="100%">
<%@ include file="/header.jsp" %>

<tr valign="top"><td align="center" height="300px">
<table width="100%">

<tr valign="top" height="50px">
<td align="center">
<%@ include file="/headerLinks.jsp" %>
</td>
</tr>
<tr><td align="center" height="40px" colspan="2" valign="top"><h3>Cart</h3></td></tr>
<% if(request.getAttribute("message") != null) { %>
<tr><td align="center" style="color:red"><%= request.getAttribute("message") %></td></tr>
<% } %>

<%if(null != request.getAttribute("CartItem")) { 
%>	
<tr>
	<td align="center">
	<table  width="90%" style="text-align:left">
		<tr>
			<td width="5%">No.</td>
			<td width="10%">Item</td>
			<td width="15%">Description</td>
			<td width="20%">Seller Information</td>
			<td width="5%">Price</td>
			<td width="10%">Available Quantity</td>
			<td width="25%">Quantity In Cart</td>
			<td width="15%">Item Total Price</td>			
		</tr>
<%	
	CartItem aoCartItem[] = (CartItem[])request.getAttribute("CartItem");
	Advertisement aoAdvert[] = (Advertisement[])request.getAttribute("Advertisement");
	int cartItemId = 0, itemId=0, quantityInCart = 0;
	int i,j;
	float total = 0;
	for(i=0;i<aoCartItem.length;i++) {
		
		cartItemId = aoCartItem[i].getCartItemId();
		itemId = aoCartItem[i].getItemId();
		quantityInCart = aoCartItem[i].getItemQuantity();
		
		for(j=0;j<aoAdvert.length;j++) {
			if(aoAdvert[j].getItemId() == itemId) {
					break;
				}
			}
		total += (aoAdvert[j].getItemPrice()*quantityInCart);
		
%>
	<form name="updateCart_<%=aoAdvert[i].getItemId()%>" action="UpdateCart" method="post">
		<tr style="text-align:left">
			<td><%=i+1%></td>
			<td><%=aoAdvert[j].getItemName() %></td>
			<td><%=aoAdvert[j].getItemDescription() %></td>
			<td><%=aoAdvert[j].getSellerInfo() %></td>
			<td><%=aoAdvert[j].getItemPrice() %></td>
			<td><%=aoAdvert[j].getItemQuantity() %><input type="hidden" name="itemQuantity" value="<%=aoAdvert[i].getItemQuantity() %>"></td>
			<td>
				<input type="text" name="orderedQuantity" value="<%=quantityInCart %>">
				<input type="submit" name="submit" value="Update">
				<input type="submit" name="submit" value="Delete">
			</td>
			<td><%=aoAdvert[j].getItemPrice()*quantityInCart %>
				
			</td>
			<input type="hidden" name="itemId" value="<%=aoAdvert[i].getItemId()%>">
			<input type="hidden" name="cartItemId" value="<%=cartItemId%>">
			<input type="hidden" name="quantityInCart" value="<%=quantityInCart%>">
			
		</tr>
	</form>		
<%	} %>
	<tr>
		<td colspan="8"></td>		
	</tr>
	<tr>
		<td colspan="8"><hr></td>		
	</tr>
	<tr>
		<td colspan="6"></td>
		<td align="left">Total</td>
		<td align="left"><%=total%></td>
	</tr>
	<tr>
		<td colspan="8" height="30px">
		</td>
	</tr>
	
	<tr>
		<td colspan="7"></td>
		<td align="left">
			<form name="checkout" action="Checkout" method="post">
				<input type="submit" name="submit" value="Checkout">
			</form>
		</td>
	</tr>
	</table>
	</td>
</tr>
<%} %>

</table>
</td>
</tr>

<%@ include file="/bottom.html" %>
</table>
</body>
</html>